<template>

    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item style="width: 60%" label="姓名" prop="name">
            <el-input v-model="ruleForm.name"></el-input>
        </el-form-item>

        <el-form-item style="width: 60%" label="学院" prop="college">
            <el-input v-model="ruleForm.college"></el-input>
        </el-form-item>

      <el-form-item style="width: 60%" label="工号" prop="ranking">
        <el-input v-model="ruleForm.ranking"></el-input>
      </el-form-item>
        <el-form-item label="奖项分类" prop="category">
            <el-cascader
                    :options="options"
                    :show-all-levels="false"
                    filterable
                    ref="myCascader"
                    @change="onProvincesChange"
                    v-model="ruleForm.category"
                    clearable></el-cascader>
        </el-form-item>
        <el-form-item style="width: 60%" label="奖项" prop="award">
            <el-input v-model="ruleForm.award"></el-input>
        </el-form-item>
        <el-form-item label="负责人" prop="category">
            <el-cascader
                    :options="options1"
                    :show-all-levels="false"
                    filterable
                    ref="mySelect"
                    @change="onProvincesChange"
                    v-model="ruleForm.charge"
                    clearable></el-cascader>
        </el-form-item>

        <el-form-item label="立项部门" prop="LiX" v-if="this.y">
            <el-cascader
                    :options="options2"
                    :show-all-levels="false"
                    filterable
                    ref="mySelect1"
                    :label-width="formLabelWidth"
                    @change="onProvincesChange"
                    v-model="ruleForm.LiX"
                    clearable></el-cascader>
        </el-form-item>

        <el-form-item label="是否再版" prop="ZaiBan" v-if="this.z">
            <el-cascader
                    :options="options3"
                    :show-all-levels="false"
                    filterable
                    ref="mySelect2"
                    :label-width="formLabelWidth"
                    @change="onProvincesChange"
                    v-model="ruleForm.ZaiBan"
                    clearable></el-cascader>
        </el-form-item>

        <el-form-item label="第一单位？" prop="Danwei" v-if="this.o">
            <el-cascader
                    :options="options4"
                    :show-all-levels="false"
                    filterable
                    ref="mySelect2"
                    :label-width="formLabelWidth"
                    @change="onProvincesChange"
                    v-model="ruleForm.Danwei"
                    clearable></el-cascader>
        </el-form-item>

        <el-form-item style="width: 60%" label="基本绩点"
                      prop="achievement"
                      :label-width="formLabelWidth"
                      v-if="this.n">
            <el-input v-model="ruleForm.achievement"></el-input>
        </el-form-item>

        <el-form-item style="width: 60%" label="总字数（万）:"
                      prop="words"
                      :label-width="formLabelWidth"
                      v-if="this.m">
            <el-input v-model="ruleForm.words" prop="words1" ></el-input>
        </el-form-item>
        <el-form-item style="width: 60%" label="总经费:"
                      prop="funds"
                      :label-width="formLabelWidth"
                      v-if="this.x">
            <el-input v-model="ruleForm.funds"></el-input>
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>

    </el-form>

</template>




<script>
    let words = [
        { required: true, message: '该奖项类型下此项为必填项', trigger: 'blur' },
    ];
    let funds = [
        { required: true, message: '该奖项类型下此项为必填项', trigger: 'blur' }
    ];
    let achievement = [
        {required: true, message:'该奖项类型下此项为必填项', trigger: 'blur'}
    ];
    let LiX = [
        {required: true, message:'该奖项类型下此项为必填项', trigger: 'blur'}
    ];
    let ZaiBan = [
        {required: true, message:'该奖项类型下此项为必填项', trigger: 'blur'}
    ];
    let Danwei =[{required: true, message:'该奖项类型下此项为必填项', trigger: 'blur'}];
    export default {
        name:"InsAdd",
        data() {
            return {
                ruleForm: {
                    name: '',
                    college: '',
                    award:'',
                    charge:'1',
                    achievement:'',
                    category: '',
                    gpa:'',
                    words:'',
                    ranking:'',
                    funds:'',
                    n:false,
                    m:false,
                    x:false,
                    y:false,
                    z:false,
                    o:false,
                    ZaiBan:'',
                    LiX:'',
                    a:''
                },
                options1: [{
                    value: '1',
                    label: '第一负责人'
                }, {
                    value: '0.5',
                    label: '第二负责人'
                }, {
                    value: '0.3',
                    label: '第三负责人'
                },{
                    value: '0.2',
                    label: '第四负责人'
                }
                ],
                options2:[{
                    value:'XueXiao',
                    label:'学校',
                },{
                    value:'XueYuan',
                    label: '学院'
                },{
                    value: 'Wu',
                    label: '未经立项'
                }],
                options3:[{
                    value:'YEs',
                    label:'是'
                },
                    {
                        value: 'No',
                        label: '否'
                    }
                ],
                options4:[
                    {
                        value:'YES',
                        label:'是'
                    },
                    {
                        value: 'NO',
                        label: '否'
                    }
                ],
                options: [{
                    value: 'JiaoYan',
                    label: '教研业绩量化',
                    children: [{
                        value: 'shejiyuanze',
                        label: '项目立项和结题',
                        children: [{
                            value: 'yizhi',
                            label: '国家级教育教学一般项目立项'
                        }, {
                            value: 'fankui',
                            label: '省级教育教学重大项目立项'
                        }, {
                            value: 'xiaolv',
                            label: '省级教育教学重点项目立项'
                        }, {
                            value: 'kekong',
                            label: '省级教育教学一般项目立项'
                        },{
                            value: 'jsad',
                            label: '国家级教育教学项目结题'
                        },{
                            value: 'jsadd',
                            label: '省级教育教学项目结题'
                        }
                            ,{
                                value: 'jasad',
                                label: '校级教育教学项目结题'
                            }
                        ]
                    }, {
                        value: 'daohang',
                        label: '专业',
                        children: [{
                            value: 'cexiangdaohang',
                            label: '工程教育专业认证通过'
                        }, {
                            value: 'dingbudaohang',
                            label: '国家级专业评估通过'
                        },{
                            value: 'dingbudaohang',
                            label: '省级专业评估通过'
                        }]

                    },
                        {
                            value: 'Kecheng',
                            label: '课程',
                            children: [{
                                value: 'Gjj',
                                label: '国家级课程建设项目立项'
                            },
                                {
                                    value:'SjKc',
                                    label: '省级课程建设项目立项'
                                },
                                {
                                    value:'XUexiaoMk',
                                    label: '学校慕课项目通过验收'
                                }
                                ,
                                {
                                    value:'XUexiaoKc',
                                    label: '学校其他课程建设项目通过验收'
                                }
                            ]
                        },{
                            value: 'LunWen',
                            label: '论文',
                            children: [{
                                value: 'XjBi',
                                label: '校级优秀毕业设计一等奖'
                            },{
                                value: 'XjBiQi',
                                label: '校级优秀毕业设计其他'
                            }
                                ,{
                                    value: 'JiaoXueGai',
                                    label: '教学改革研究论文（核心期刊）'
                                },{
                                    value: 'JiaoXueGaiQi',
                                    label: '教学改革研究论文（其它）'
                                }]
                        },{
                            value: "HuoJiang",
                            label: '获奖',
                            children: [{
                                value: 'Gt',
                                label: '国家级特等奖'
                            },{
                                value: 'GY',
                                label: '国家级一等奖'
                            },{
                                value: 'GE',
                                label: '国家级二等奖'
                            },{
                                value: 'St',
                                label: '省级特等奖'
                            },{
                                value: 'Sy',
                                label: '省级一等奖'
                            },{
                                value: 'Se',
                                label: '省级二等奖'
                            },{
                                value: 'XJT',
                                label: '校教学成果特等奖'
                            },{
                                value: 'XJY',
                                label: '校教学成果一等奖'
                            },{
                                value: 'XJE',
                                label: '校教学成果二等奖'
                            }]
                        }]
                }, {
                    value: 'JiaoCai',
                    label: '教材业绩量化',
                    children: [{
                        value: 'GjGui',
                        label: '国家级规划教材',
                        children: [{
                            value: 'ZhongWen',
                            label: '中文编写',
                            children:[{
                                value:'Zb+Zb',
                                label:'本校第一执笔（第一主编）'
                            },{
                                value: 'Zb',
                                label: '本校第一执笔'
                            },{
                                value: 'WxZb+Zb',
                                label: '外校第一执笔（第一主编）'

                            },{
                                value: 'WxZb',
                                label: '外校第一执笔'
                            }]
                        }, {
                            value: 'Waiyu',
                            label: '外语编写',
                            children:[{
                                value:'Zb+Zb',
                                label:'本校第一执笔（第一主编）'
                            },{
                                value: 'Zb',
                                label: '本校第一执笔'
                            },{
                                value: 'WxZb+Zb',
                                label: '外校第一执笔（第一主编）'

                            },{
                                value: 'WxZb',
                                label: '外校第一执笔'
                            }]
                        }]
                    }, {
                        value: 'SjGh',
                        label: '省级规划教材',
                        children: [{
                            value: 'ZhongWen',
                            label: '中文编写',
                            children:[{
                                value:'Zb+Zb',
                                label:'本校第一执笔（第一主编）'
                            },{
                                value: 'Zb',
                                label: '本校第一执笔'
                            },{
                                value: 'WxZb+Zb',
                                label: '外校第一执笔（第一主编）'

                            },{
                                value: 'WxZb',
                                label: '外校第一执笔'
                            }]
                        }, {
                            value: 'Waiyu',
                            label: '外语编写',
                            children:[{
                                value:'Zb+Zb',
                                label:'本校第一执笔（第一主编）'
                            },{
                                value: 'Zb',
                                label: '本校第一执笔'
                            },{
                                value: 'WxZb+Zb',
                                label: '外校第一执笔（第一主编）'

                            },{
                                value: 'WxZb',
                                label: '外校第一执笔'
                            }]
                        }]
                    }, {
                        value: 'QiTa',
                        label: '其他教材',
                        children: [{
                            value: 'ZhongWen',
                            label: '中文编写',
                            children:[{
                                value:'Zb+Zb',
                                label:'本校第一执笔（第一主编）'
                            },{
                                value: 'Zb',
                                label: '本校第一执笔'
                            },{
                                value: 'WxZb+Zb',
                                label: '外校第一执笔（第一主编）'

                            },{
                                value: 'WxZb',
                                label: '外校第一执笔'
                            }]
                        }, {
                            value: 'Waiyu',
                            label: '外语编写',
                            children:[{
                                value:'Zb+Zb',
                                label:'本校第一执笔（第一主编）'
                            },{
                                value: 'Zb',
                                label: '本校第一执笔'
                            },{
                                value: 'WxZb+Zb',
                                label: '外校第一执笔（第一主编）'

                            },{
                                value: 'WxZb',
                                label: '外校第一执笔'
                            }]
                        }]
                    }, ]
                }, {
                    value: 'ZiRan',
                    label: '自然科学科研业绩量化',
                    children: [{
                        value: 'KyXm',
                        label: '科研项目',
                        children: [{
                            value: 'GjXm',
                            label: '国家级'
                        },{
                            value: "SjXm",
                            label: '省级',
                        },{
                            value: 'Sj',
                            label: '市级'
                        },{
                            value: 'HX',
                            label: '横向项目',
                            children: [{
                                value: 'Hx300',
                                label: '横向项目（≥300万元）'
                            },{
                                value: 'Hx80',
                                label: '横向项目（≥80万元，<300万元）',
                            },{
                                value: 'Hx0',
                                label: '横向项目（80万元以下）'
                            }]
                        }
                        ]
                    }, {
                        value: 'KyCg',
                        label: '科研成果业绩量化',
                        children: [{
                            value:'BZYJLH',
                            label:'标准业绩量化',
                            children: [{
                                value: 'GjBZ',
                                label: '国家标准'
                            },{
                                value: 'HyBz',
                                label: '行业标准'
                            },{
                                value: 'DiFangBz',
                                label: '地方标准'
                            },{
                                value: 'QiYeBz',
                                label: '企业标准'
                            }
                            ]
                        },/*{
              value: 'KyJl',
              label: '科研奖励的业绩量化',
              children: [{
                value:'GjKx',
                label: '国家科学技术奖励',
              },{
                value:'JYB,SkX',
                label: '教育部、省科学技术奖励'
              },{
                value: 'ZGFZ',
                label: '中国纺织工业联合会科学技术奖励'
              },{
                value: 'SZlJ',
                label: '省专利奖'
              },{
                value: '',
                label: '国家奖励办\n' +
                    '登记的社会力量设奖\n'
              },{
                value: 'STJ',
                label: '市厅级'
              },{
                value: 'HNSZRKX',
                label: '河南省自然科学学术奖'
              }]
            }*/]
                    }, ]
                }],

                rules: {
                    name: [
                        { required: true, message: '请输入您的姓名', trigger: 'blur' },
                        { min: 2, max: 5, message: '长度在 2到 5 个字符', trigger: 'blur' }
                    ],
                    college: [
                        { required: true, message: '请输入您的学院', trigger: 'blur' }
                    ],
                  ranking: [
                    { required: true, message: '请输入您的工号', trigger: 'blur' }
                  ],
                    category: [
                        {required: true, message: '请选择分类', trigger: 'change'}
                    ],
                    award: [
                        { required: true, message: '请输入您的奖项', trigger: 'blur' }
                    ],
                    charge: [
                        { required: true, message: '请输入', trigger: 'blur' }
                    ],
                    achievement: [{ trigger: 'blur' }],
                    words: [{ trigger: 'blur' }],
                    funds: [{ trigger: 'blur' }],
                    LiX: [{ trigger: 'blur' }],
                    ZaiBan: [{ trigger: 'blur' }],
                    Danwei: [{ trigger: 'blur' }],
                },

            };





        },
        methods: {
            submitForm(formName) {
                const _this = this
                const newForm=JSON.parse(JSON.stringify(this.ruleForm))
                let n=parseFloat(newForm.charge)
                newForm.category=this.$refs.myCascader.getCheckedNodes()[0].label
                newForm.charge=this.$refs.mySelect.getCheckedNodes()[0].label
                let arr = this.$refs['myCascader'].getCheckedNodes()[0].pathLabels
                let v1 =newForm.LiX
                let v2 =newForm.ZaiBan
                let v3=newForm.Danwei
                let m2=1
                let m3=1
                let m4
                if(newForm.words>60){
                    newForm.words=60
                }
                if (v1=='XueXiao'){
                    m2=1
                }
                else if(v1=='XueYuan'){
                    m2=0.5
                }
                else if(v1=='Wu'){
                    m2=0
                }
                if (v2=="YEs"){
                    m3=1
                }
                else{
                    m3=0.5
                }
                if(v3=="YES"){
                    m4=1
                }
                else {
                    m4=0.5
                }
                if(arr[0]=="教研业绩量化"){
                    if(arr[1]=="获奖"){
                        newForm.gpa=n*newForm.achievement;
                    }
                    else {
                        newForm.gpa=newForm.achievement;
                    }
                }
                else if(arr[0]=="教材业绩量化"){
                  newForm.achievement=newForm.words
                    if(arr[1]=='国家级规划教材'){
                        if (arr[2]=='中文编写'){
                            if(arr[3]=='本校第一执笔（第一主编）'){
                                newForm.gpa=3.5*3.5*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='本校第一执笔'){
                                newForm.gpa=3*3.5*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='外校第一执笔（第一主编）'){
                                newForm.gpa=1.5*3.5*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='外校第一执笔'){
                                newForm.gpa=0.5*3.5*newForm.achievement*m2*m3;
                            }
                        }
                        else if(arr[2]=='外语编写'){
                            if(arr[3]=='本校第一执笔（第一主编）'){
                                newForm.gpa=3.5*3.5*1.2*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='本校第一执笔'){
                                newForm.gpa=3*3.5*1.2*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='外校第一执笔（第一主编）'){
                                newForm.gpa=1.5*3.5*1.2*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='外校第一执笔'){
                                newForm.gpa=0.5*3.5*1.2*newForm.achievement*m2*m3;
                            }
                        }
                    }
                    else if(arr[1]=='省级规划教材'){
                        if (arr[2]=='中文编写'){
                            if(arr[3]=='本校第一执笔（第一主编）'){
                                newForm.gpa=3.5*2*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='本校第一执笔'){
                                newForm.gpa=3*2*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='外校第一执笔（第一主编）'){
                                newForm.gpa=1.5*2*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='外校第一执笔'){
                                newForm.gpa=0.5*2*newForm.achievement*m2*m3;
                            }
                        }
                        else if(arr[2]=='外语编写'){
                            if(arr[3]=='本校第一执笔（第一主编）'){
                                newForm.gpa=3.5*2*1.2*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='本校第一执笔'){
                                newForm.gpa=3*2*1.2*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='外校第一执笔（第一主编）'){
                                newForm.gpa=1.5*2*1.2*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='外校第一执笔'){
                                newForm.gpa=0.5*2*1.2*newForm.achievement*m2*m3;
                            }
                        }

                    }
                    else if(arr[1]=='其他教材'){
                        if (arr[2]=='中文编写'){
                            if(arr[3]=='本校第一执笔（第一主编）'){
                                newForm.gpa=3.5*2*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='本校第一执笔'){
                                newForm.gpa=3*2*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='外校第一执笔（第一主编）'){
                                newForm.gpa=1.5*2*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='外校第一执笔'){
                                newForm.gpa=0.5*2*newForm.achievement*m2*m3;
                            }
                        }
                        else if(arr[2]=='外语编写'){
                            if(arr[3]=='本校第一执笔（第一主编）'){
                                newForm.gpa=3.5*2*1.2*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='本校第一执笔'){
                                newForm.gpa=3*2*1.2*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='外校第一执笔（第一主编）'){
                                newForm.gpa=1.5*2*1.2*newForm.achievement*m2*m3;
                            }
                            else if(arr[3]=='外校第一执笔'){
                                newForm.gpa=0.5*2*1.2*newForm.achievement*m2*m3;
                            }
                        }

                    }
                }
                else if(arr[0]=='自然科学科研业绩量化'){
                    if (arr[1]=='科研项目'){
                        newForm.achievement=newForm.funds*0.0005
                        if(arr[2]=='国家级'){

                            newForm.gpa=newForm.achievement*4;

                        }
                        else if (arr[2]=='省级'){
                            newForm.gpa=newForm.achievement*3;
                        }
                        else if (arr[2]=='市级'){
                            newForm.gpa=newForm.achievement*2;
                        }
                        else if (arr[2]=='横向项目'){
                            if (arr[3]=='横向项目（≥300万元）'){
                                newForm.gpa=newForm.achievement*1.2;
                            }
                            else if(arr[3]=='横向项目（≥80万元，<300万元）'){
                                newForm.gpa=newForm.achievement*1.1;
                            }
                            else if(arr[3]=='横向项目（80万元以下）'){
                                newForm.gpa=newForm.achievement*1.0;
                            }
                        }
                    }
                    else if(arr[1]=='科研成果业绩量化'){
                        if(arr[2]=='标准业绩量化'){
                            if(newForm.charge=='第一负责人'){
                                newForm.gpa=newForm.achievement*m4;
                            }
                            else{
                                newForm.gpa=newForm.achievement*m4*0.5;
                            }
                        }
                    }
                }
                newForm.a=arr[0]
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                      this.$axios.post('/statics/save/',newForm)
                        this.$axios.post('/ins/save/',newForm).then( resp => {
                            if(resp.data == 'success'){
                                _this.$message({
                                    showClose: true,
                                    message: '提交成功',
                                    type: 'success',
                                });
                                _this.$router.push('/ins/findAll/1/6')
                            }
                        })

                    } else {
                        alert('提交失败!!');
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        },
        watch: {
            "ruleForm.category": function (val) {
                this.val = val
                this.n = true
                this.m = false
                this.x = false
                this.y = false
                this.z = false
                this.o = false
                Object.assign(this.rules, {
                    achievement,
                });
                /*     setTimeout(() => { // 添加事件队列
                       this.$refs.ruleForm.validateField(["achievement"]);
                       this.$refs.ruleForm.clearValidate(["database", "servername"]);
                     }, 0);*/

                if (val[0] == 'JiaoCai') {
                    this.n=false
                    this.m=true
                    this.x=false
                    this.y=true
                    this.z=true
                    Object.assign(this.rules, {
                        words,
                        LiX,
                        ZaiBan
                    });

                    /*   setTimeout(() => { // 添加事件队列
                         this.$refs.ruleForm.validateField(["servername","LiX","ZaiBan"]);
                         this.$refs.ruleForm.clearValidate(["database","achievement"]);
                       }, 0);*/
                    /*   setTimeout(() => { // 添加事件队列
                         this.$refs.ruleForm.validateField(["servername","LiX","ZaiBan"]);
                         this.$refs.ruleForm.clearValidate(["database","achievement"]);
                       }, 0);*/
                }
                else  if(val[1] == 'KyXm') {
                    this.n=false
                    this.m=false
                    this.x=true
                    Object.assign(this.rules, {
                        funds,
                    });

                    /*      setTimeout(() => { // 添加事件队列很重要
                            //this.$refs.formInline.validateField(["mysqlName"]);
                            this.$refs.ruleForm.validateField(["database"]);
                            this.$refs.ruleForm.clearValidate(["servername","achievement"])
                          }, 0);*/
                }
                else if(val[2] == 'BZYJLH'){
                    this.o=true
                    Object.assign(this.rules, {
                        Danwei
                    });
                }
            },
            "ruleForm.words":function (label) {
                this.label=label
                if(this.label>60){
                    this.$message({
                        showClose: true,
                        message: '字数最多计入60万字',
                        type: 'warning',
                    });
                }
            }
        }
    }



</script>



<style scoped>

</style>